package day28_239;

import java.util.*;

/**
 * @ClassName Solution
 * @Description 超时
 * @Author clockTown
 * @Date 2021/6/6 18:55
 * @Version 1.0
 */
public class Solution1 {
    public static int[] maxSlidingWindow(int[] nums, int k) {
        //判断特例
        if (nums.length == 1 || k == 1) {
            return nums;
        }

        List<Integer> resList = new ArrayList<>();
        PriorityQueue<Integer> queue = new PriorityQueue(k, Comparator.reverseOrder());

        for (int i = 0; i < nums.length; i++) {
            if (queue.size() == k) {
                queue.remove(nums[i - k]);
            }
            queue.add(nums[i]);
            if (i >= k - 1) {
                resList.add(queue.peek());
            }
        }
        int[] res = new int[resList.size()];
        for (int i = 0; i < res.length; i++) {
            res[i] = resList.get(i);
        }

        return res;
    }
}
